import sys,os,cgi,time
sys.path.insert(0, os.path.split(sys.path[0])[0])
import cnd
import tag

import re

form = cgi.FieldStorage()

if False:
	print "HTTP/1.1 200 ok"
	print "Content-Type: text/html"     # HTML is following
	print
else:
	import head
	head.header(banner=False,action='action',tags=[])

action=''
kind=''
jd = []

for k in form.keys():
	if k=='action':
		action=form.getfirst(k).lower()
	elif k=='kind':
		kind=form.getfirst(k).lower()
	elif re.match("^\d{8}$",form.getfirst(k)):
		j = k.lower()
		for d in form.getlist(k):
			jd += [(j,d)]

print "<h2>Mass action summary</h2>"
print "<pre>"
for j,d in jd:
	c=j+'.'+kind
	if action=='add':
		cnd.add(c,d)
	elif action=='remove':
		cnd.clear(c,d)
	print action,d,c
print "</pre>"
